package com.ichart.doc;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * parse method
 *
 * create at 2012-6-12 下午05:53:11
 * @author wanghe
 */
public class Method {
	private String method;
	private String annotation;
	private String definedBy;
	private String fullName;
	List<Item> paramters = new ArrayList<Item>();
	private Item returnValue;
	public static Pattern ANNOTATION = Pattern.compile("^(.*?)(@paramter|@return)",Pattern.DOTALL);
	public static Pattern PARAMTER = Pattern.compile("@paramter\\s*(.*)#(\\w*)\\s*(.*)$", Pattern.MULTILINE);
	public static Pattern RETURN = Pattern.compile("@return\\s*(.*)$", Pattern.MULTILINE);
	
	
	public Method(String desc,String method,String definedBy, String fullName) {
		Matcher m1 = ANNOTATION.matcher(desc);
		while(m1.find()){  
			this.annotation = m1.group(1).trim();
			if(this.annotation.endsWith("*"))
				this.annotation = this.annotation.substring(0,this.annotation.length()-1);
			this.annotation = this.annotation.trim();
        }
		
		Matcher m2 = PARAMTER.matcher(desc);
		while(m2.find()){  
			paramters.add(new Item(m2.group(1),m2.group(2),m2.group(3)));
        }
		
		Matcher m3 = RETURN.matcher(desc);
		while(m3.find()){  
			returnValue = new Item("","",m3.group(1));
        }
		
		this.method = method;
		this.definedBy = definedBy;
		this.fullName = fullName;
	}
	
	

	public void put(String attribute, String type, String annotation){
		paramters.add(new Item(attribute,type,annotation));
	}
	
	public String getMethod() {
		return method;
	}



	public void setMethod(String method) {
		this.method = method;
	}



	public String getAnnotation() {
		return annotation;
	}
	public void setAnnotation(String annotation) {
		this.annotation = annotation;
	}
	public String getDefinedBy() {
		return definedBy;
	}
	public void setDefinedBy(String definedBy) {
		this.definedBy = definedBy;
	}
	public String getFullName() {
		return fullName;
	}
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
	public List<Item> getParamters() {
		return paramters;
	}
	public void setParamters(List<Item> paramters) {
		this.paramters = paramters;
	}



	public Item getReturnValue() {
		return returnValue;
	}


	public void setReturnValue(Item returnValue) {
		this.returnValue = returnValue;
	}
	

	
	
	
}
